package com.yu.waterstation.app.moudles.address.controller;

import com.yu.waterstation.app.moudles.address.mapper.AddressMapper;
import com.yu.waterstation.app.moudles.address.service.AddressServiceImpl;
import com.yu.waterstation.common.common.annotation.VisitorAccess;
import com.yu.waterstation.common.common.util.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = "地址")
@RestController
@RequestMapping("/address")
public class AddressController {
    @Resource
    private AddressServiceImpl addressService;
    @Resource
    private AddressMapper addressMapper;

    @ApiOperation("获取寝室选择树")
    @VisitorAccess
    @GetMapping("/tree")
    public Result getAddressTree() {
        return Result.ok(addressService.getAddressTree());
    }

    @ApiOperation("寝室的详细信息")
    @VisitorAccess
    @GetMapping("/{addressId}")
    public Result getAddressDetail(@ApiParam("地址id") @PathVariable Integer addressId) {
        return Result.ok(addressService.getAddressDetail(addressId));
    }

    @ApiOperation("寝室成员")
    @VisitorAccess
    @GetMapping("/{addressId}/student")
    public Result getAddressStudents(@PathVariable Integer addressId) {
        return Result.ok(addressMapper.getAddressStudents(addressId));
    }

    @ApiOperation("所有楼舍")
    @VisitorAccess
    @GetMapping("/dorm/list")
    public Result getALlAreas() {
        return Result.ok(addressService.getAllDorms());
    }


}

